package com.takeshequ.homepage;

import java.util.HashMap;
import java.util.Map;

import net.tsz.afinal.annotation.view.ViewInject;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;

import com.takeshequ.BasicActivity;
import com.takeshequ.Constants;
import com.takeshequ.R;
import com.utils.HttpClientUtils;
import com.utils.HttpClientUtils.HttpResponseHandler;

public class HomePageEditActivity extends BasicActivity {
	@ViewInject(id = R.id.homepage_back, click = "back")
	private Button back;

	@ViewInject(id = R.id.homepage_edit_save_btn, click = "save")
	private ImageButton save;

	@ViewInject(id = R.id.homepage_edit_my_car)
	private EditText myCar;
	@ViewInject(id = R.id.homepage_edit_favorite_car)
	private EditText favoriteCar;

	@ViewInject(id = R.id.homepage_edit_signature)
	private EditText signature;

	@ViewInject(id = R.id.homepage_edit_job)
	private EditText job;

	private Member member;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.homepage_edit);
		member = Constants.member;
	}

	@Override
	protected void onResume() {
		super.onResume();
		myCar.setText(member.getMyCars());
		favoriteCar.setText(member.getLikeCars());
		signature.setText(member.getSignature());
		job.setText(member.getJob());

	}

	public void back(View v) {
		overridePendingTransition(R.anim.push_right_out, R.anim.push_left_in);
		startActivity(new Intent(HomePageEditActivity.this,
				HomePageActivity.class));
	}

	public void save(View v){
		Map<String,String> params=new HashMap<String,String>();
		params.put("memberId",member.getMemberId());
		params.put("job",job.getText().toString().trim());
		params.put("myCars",myCar.getText().toString().trim());
		params.put("likeCars",favoriteCar.getText().toString().trim());
		params.put("signature",signature.getText().toString().trim());
		HttpClientUtils.post(HomePageEditActivity.this,"正在更新....","/updateMemberInfo", params, new HttpResponseHandler() {
			
			@Override
			public void handler(String response) {
				System.out.println(response);
				back(null);
			}
		});
	}
}
